#ifndef __EFFECTS_PASS_H__
#define __EFFECTS_PASS_H__

#include "FBO.h"
#include "shaderUtils.h"
#include <map>

namespace glutil
{

	/** Class used to do a full screen pass with a GLSL shader, using a series of textures 
	  as input, and an FBO or the backbuffer as output*/
	class EffectsPass
	{
		public:
			/** Constructor
			  @param program Shader program to use in the pass
			  @param destinationBuffer FBO in which to store the pass results. If it's left to NULL, the back buffer will be used instead*/
			EffectsPass(ShaderProgram * program, FBO * destinationBuffer = NULL) : m_program(program), m_destination(destinationBuffer) {}
			/** Sets the texture to be bound to a certain texture unit */
			void setTexture(int textureUnit, FBO * texture);
			/** Does a pass for a viewport of the specified dimensions */
			void doPass(int viewportWidth, int viewportHeight);
			/** Destructor */
			virtual ~EffectsPass(){}

		private:
			void set2DCamera();

			ShaderProgram * m_program;
			FBO *m_destination;
			std::map<int, FBO *> m_textures;
	};

	/** Utility class left here from old times. It's just a wrapper for EffectsClass, but only allows for 1 texture as input */
	class EffectsPass1to1 : public EffectsPass
	{
		public:
			/** Constructor
			  @param program Shader program to use in the pass
				@param originalBuffer Texture to be used as input
			  @param destinationBuffer FBO in which to store the pass results. If it's left to NULL, the back buffer will be used instead*/
			EffectsPass1to1(ShaderProgram * program, FBO * originalBuffer, FBO * destinationBuffer = NULL) : EffectsPass(program, destinationBuffer)
			{
				setTexture(0,originalBuffer);
			}
			/** Destructor */
			~EffectsPass1to1(){}
	};

	/** Utility class left here from old times. It's just a wrapper for EffectsClass, but only allows for 2 textures as input */
	class EffectsPass2to1 : public EffectsPass
	{
		public:
			/** Constructor
			  @param program Shader program to use in the pass
			  @param originalBuffer1 First texture to be used as input
			  @param originalBuffer2 Second texture to be used as input
			  @param destinationBuffer FBO in which to store the pass results. If it's left to NULL, the back buffer will be used instead*/

			EffectsPass2to1(ShaderProgram * program, FBO * originalBuffer1, FBO * originalBuffer2, FBO * destinationBuffer = NULL ) : EffectsPass(program,destinationBuffer)
			{
				setTexture(0,originalBuffer1);
				setTexture(1,originalBuffer2);
			}
	}; 

}
#endif

